Skip to content

Conversation

@amerjusupovic
Copy link
Contributor

@amerjusupovic amerjusupovic commented May 16, 2024

Emits the feature flag schema defined here.

Added to avoid resolving conflicts with main branch, main will be merged in after to ensure necessary tests are added and branches are up to date.

@amerjusupovic amerjusupovic marked this pull request as ready for review May 29, 2024 20:00
@amerjusupovic
Copy link
Contributor Author

I'll be adding more unit tests

@amerjusupovic amerjusupovic requested a review from rossgrambo June 3, 2024 18:04
""variant"": ""Big"",
""users"": [
""Marsha"",
""John""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation inconsistent throughout this file. Might be worth running dotnet format on it.

Copy link
Contributor Author

@amerjusupovic amerjusupovic Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to do this now, looks like it doesn't work the same with strings within code unless I missed something. I could try to fix it manually too, just not sure if there's a better way

expectedJsonValueKind));
}

private FeatureFlag ParseFeatureFlag(string settingKey, string settingValue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like us having to do this manually. Did we look into source generation as an alternative? https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/reflection-vs-source-generation?pivots=dotnet-8-0#reflection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, it does require a lot more testing and is more code to maintain. One reason to continue with this approach is it follows the pattern we established in our other .NET repos of always using Utf8JsonReader for reading Json, which is more efficient compared to the JsonSerializer.Deserialize method. Also, we already added it to the main branch without variants/allocation/telemetry and this PR is re-adding it for merge conflict purposes.

I'm not sure, but from what I can tell here it looks like source generation isn't available in all of the versions we support, since it's only for C# 9.0 and later, and .NET 6.0 and later.

@avanigupta avanigupta linked an issue Jun 10, 2024 that may be closed by this pull request

string userAllocationPropertyName = reader.GetString();

switch (userAllocationPropertyName)
Copy link
Member

@zhiyuanliang-ms zhiyuanliang-ms Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we handle the case that one of variant and users is missing? For example,

"allocation": {
    "user": [
        {
            "users": ["a","b"]
        }
    ]
}

This user allocation will not take effect. Do we still need to put it in the configuration or throw exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I think it should check to see if they aren't empty, so if there's anything inside of "user", either a list of users or a variant name, then it would be added. I thought since we shouldn't necessarily be doing any feature management logic, it would make sense to just exclude it if it's completely empty, but otherwise add the object. So in this case that you put up, I think it should be added. I don't think we need to throw an exception though, since we never did something like that if conditions was empty, for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Amer here. Feature Management library is responsible for checking the validity of a feature flag. Provider library just reads and flattens whatever is stored in AppConfig.

amerjusupovic and others added 3 commits June 11, 2024 10:15
…onstants/ErrorMessages.cs

Co-authored-by: Zhiyuan Liang <141655842+zhiyuanliang-ms@users.noreply.github.com>
if (featureManagementVersion != null)
{
// If the version is less than 3.2.0, log the schema version warning
if (featureManagementVersion < new Version(3, 2, 0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Min version could be a constant variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't actually make it a constant because the value is new Version(), but I could just put FeatureManagementMinimumVersion as a readonly class variable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was imagining a const string "3.2.0" which is local to this method. And we use Version.Parse to compare versions.


[JsonPropertyName("from")]
public double From { get; set; }
public double? From { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From and To are required fields. Why change to nullable?

Copy link
Contributor Author

@amerjusupovic amerjusupovic Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point, I was thinking to do that so we could tell if they were set later on in the code when the percentile object is added to the key values output, but I don't think there's a point in doing that anyway. They should just be 0 by default like it was before. Regardless it should be wrong to be nullable if they're required


bool NeedsRefresh();

void ResetState();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface is accumulating too many methods that apply only to a particular implementation. I'm wondering if we should repurpose the InvalidateCache method instead of introducing a new one. We could rename it to something like ResetInternalState(ConfigurationSetting setting = null) so that it fits both use cases. In all situations, we call this method before processing adapters.

cc @jimmyca15

Copy link
Contributor Author

@amerjusupovic amerjusupovic Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right that at least something should change here - having the new method seems weird since it's just for this one case. I think a rename works based on where we're calling InvalidateCache now and where the state needs to reset for the FeatureManagementKeyValueAdapter anyway.

if (featureManagementVersion != null)
{
// If the version is less than 3.2.0, log the schema version warning
if (featureManagementVersion < new Version(3, 2, 0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was imagining a const string "3.2.0" which is local to this method. And we use Version.Parse to compare versions.

amerjusupovic and others added 2 commits June 18, 2024 10:33
…onstants/LoggingConstants.cs

Co-authored-by: Avani Gupta <avanigupta@users.noreply.github.com>
…onstants/LoggingConstants.cs

Co-authored-by: Avani Gupta <avanigupta@users.noreply.github.com>
Comment on lines 18 to 20
void OnConfigurationRefresh(ConfigurationSetting setting = null);

void OnConfigurationUpdated();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about OnChangeDetected and OnConfigUpdated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I think that's clearer for the first one

@amerjusupovic amerjusupovic merged commit c437c87 into preview Jun 21, 2024
@amerjusupovic amerjusupovic deleted the ajusupovic/use-microsoft-featureflag-schema branch June 21, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Microsoft feature flag schema

5 participants